/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vlcj.tutorial2;

import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import java.io.File;
import javax.swing.JFileChooser;
import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.headless.HeadlessMediaPlayer;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;

/**
 *
 * @author manoelneto
 */
public class StreamHttp extends VlcjTest {

    public static void main(String[] args) throws Exception {
        
 NativeLibrary.addSearchPath(
      RuntimeUtil.getLibVlcLibraryName(), "C:\\Program Files\\VideoLAN\\VLC");
    Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
        
        JFileChooser j = new JFileChooser();
        j.showOpenDialog(null);
      
        final File f = j.getSelectedFile();
        String media = f.getPath();
       
        String options = formatHttpStream("10.103.14.53", 5555);

        System.out.println("Streaming '" + media + "' to '" + options + "'");

        MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory(args);
        HeadlessMediaPlayer mediaPlayer = mediaPlayerFactory.newHeadlessMediaPlayer();
        mediaPlayer.playMedia(media, options);

        // Don't exit
        Thread.currentThread().join();
    }

    private static String formatHttpStream(String serverAddress, int serverPort) {
        StringBuilder sb = new StringBuilder(60);
        sb.append(":sout=#duplicate{dst=std{access=http,mux=ts,");
        sb.append("dst=");
        sb.append(serverAddress);
        sb.append(':');
        sb.append(serverPort);
        sb.append("}}");
        return sb.toString();
    }
}